home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / ext2_200.zip / EXT2_SRC.ZIP / 32BITS / EXT2-OS2 / FSD32 / FS32_ALL.C < prev    next >
C/C++ Source or Header  |  1996-09-21  |  5KB  |  161 lines

  1. //
  2. // $Header: D:/32bits/ext2-os2/fsd32/RCS/fs32_allocatepagespace.c,v 1.1 1996/09/21 22:23:57 Willm Exp Willm $
  3. //
  4.  
  5. // 32 bits OS/2 device driver and IFS support driver. Provides 32 bits kernel
  6. // services (DevHelp) and utility functions to 32 bits OS/2 ring 0 code
  7. // (device drivers and installable file system drivers).
  8. // Copyright (C) 1995, 1996 Matthieu WILLM
  9. //
  10. // This program is free software; you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation; either version 2 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program; if not, write to the Free Software
  22. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. #ifdef __IBMC__
  25. #pragma strings(readonly)
  26. #endif
  27.  
  28.  
  29. #define INCL_DOS
  30. #define INCL_DOSERRORS
  31. #define INCL_NOPMAPI
  32. #include <os2.h>
  33.  
  34. #include <string.h>
  35.  
  36. #include <os2/types.h>
  37. #include <os2/StackToFlat.h>
  38. #include <os2/fsd32.h>
  39. #include <os2/fsh32.h>
  40. #include <os2/DevHlp32.h>
  41.  
  42. #include <linux/stat.h>
  43.  
  44. #include <os2/os2proto.h>
  45. #include <os2/ifsdbg.h>
  46. #include <os2/filefind.h>
  47. #include <os2/errors.h>
  48. #include <os2/log.h>
  49. #include <os2/volume.h>
  50. #include <os2/files.h>
  51. #include <os2/os2misc.h>
  52. #include <os2/trace.h>
  53.  
  54. #include <linux/fs.h>
  55. #include <linux/fs_proto.h>
  56. #include <linux/ext2_fs.h>
  57. #include <linux/ext2_proto.h>
  58. #include <linux/sched.h>
  59.  
  60. extern int swap_in_progress;
  61.  
  62. int do_allocatepagespace(struct sffsi32 *psffsi, union sffsd32 *psffsd, unsigned long ulSize) {
  63.     int                 rc = NO_ERROR;
  64.     struct file        *f;
  65.     struct buffer_head *bh;
  66.     unsigned long       tmp;
  67.     blk_t               start, end, i;
  68.     int                 err;
  69.  
  70.  
  71.     if (trace_FS_ALLOCATEPAGESPACE) {
  72.         kernel_printf("FS_ALLOCATEPAGESPACE pre-invocation - size=%lu", ulSize);
  73.     }
  74.  
  75.     /*
  76.      * Increments the swap flag
  77.      */
  78.     swap_in_progress ++;
  79.  
  80.     /*
  81.      * Gets the file structure from psffsd
  82.      */
  83.     if ((f = psffsd->f) != 0) {
  84.  
  85.         /*
  86.          * Updates the I-node
  87.          */
  88.         tmp = f->f_inode->i_size;
  89.         f->f_inode->i_size       = ulSize;
  90.         if (ulSize < tmp) {
  91.             f->f_inode->i_op->truncate(f->f_inode);
  92.         } else {
  93.             start = tmp / f->f_inode->i_sb->s_blocksize;
  94.             end   = (ulSize + f->f_inode->i_sb->s_blocksize - 1) / f->f_inode->i_sb->s_blocksize;
  95.             for (i = start; i < end; i++) {
  96.                 bh = ext2_getblk (f->f_inode, i, 1, __StackToFlat(&err));
  97.                 if (bh) {
  98.                     bforget(bh);
  99.                 } else {
  100.                     ulSize = i * f->f_inode->i_sb->s_blocksize;
  101.                     f->f_inode->i_size = ulSize;
  102.                     rc  = map_err(err);
  103.                     i = end + 1;
  104.                 }
  105.             }
  106.         }
  107.  
  108.  
  109.         f->f_inode->i_mtime      = CURRENT_TIME;
  110.         f->f_inode->i_dirt       = 1;
  111.  
  112.         /*
  113.          * Updates the SFT
  114.          */
  115.         psffsi->sfi_size            = ulSize;
  116.         psffsi->sfi_tstamp         |= ST_PWRITE;
  117.  
  118.         /*
  119.          * Commits changes to disk
  120.          */
  121.         VFS_fsync(f);
  122.     } else {
  123.         rc = ERROR_INVALID_PARAMETER;
  124.     }
  125.  
  126.     /*
  127.      * Decrements the swap flag
  128.      */
  129.     swap_in_progress --;
  130.  
  131.     if (trace_FS_ALLOCATEPAGESPACE) {
  132.         kernel_printf("FS_ALLOCATEPAGESPACE post-invocation - rc = %d", rc);
  133.     }
  134.     return rc;
  135. }
  136.  
  137. /*
  138.  * struct fs32_allocatepagespace_parms {
  139.  *     unsigned long ulWantContig; 
  140.  *     unsigned long ulSize;
  141.  *     PTR16 psffsd;
  142.  *     PTR16 psffsi;
  143.  * };
  144.  */
  145. int FS32ENTRY fs32_allocatepagespace(struct fs32_allocatepagespace_parms *parms) {
  146.     struct sffsi32 *psffsi;
  147.     union  sffsd32 *psffsd;
  148.     int             rc;
  149.  
  150.  
  151.     parms = __StackToFlat(parms);
  152.  
  153.     if ((rc = DevHlp32_VirtToLin(parms->psffsi, __StackToFlat(&psffsi))) == NO_ERROR) {
  154.         if ((rc = DevHlp32_VirtToLin(parms->psffsd, __StackToFlat(&psffsd))) == NO_ERROR) {
  155.             rc = do_allocatepagespace(psffsi, psffsd, parms->ulSize);
  156.         }
  157.     }
  158.  
  159.     return rc;
  160. }
  161.